﻿using System.Collections.Generic;

namespace Battle
{
    public interface IState
    {
        bool OnTransition(FsmContext context, ref FsmState nxt);

        void OnUpdate(FsmContext context);

        void EnterState(FsmContext context);

        void ExitState(FsmContext context);
    }


    public abstract class BaseState : IState
    {
        protected readonly FsmState state;
        protected readonly List<BaseTransition> transitions = new List<BaseTransition>();


        protected BaseState()
        {

        }

        public void AddTransition(BaseTransition b)
        {
            transitions.Add(b);
        }

        public virtual bool OnTransition(FsmContext context, ref FsmState nxt)
        {
            for (var i = 0; i < transitions.Count; ++i)
            {
                if (transitions[i].Transite(context, ref nxt))
                    return true;
            }
            return false;
        }

        public abstract void OnUpdate(FsmContext context);

        public abstract void EnterState(FsmContext context);

        public abstract void ExitState(FsmContext context);
    }



}

